mini.parse();

function PwdQuesFormHandler() {
};

PwdQuesFormHandler.instance = new PwdQuesFormHandler();

//获得全局的密保问题表单对象
PwdQuesFormHandler.pwdQuesForm = new mini.Form("pwdQuesForm");
PwdQuesFormHandler.formData = {};

// 问题状态数据
PwdQuesFormHandler.bpqStateData = [
	{text: "有效",value: 1},
	{text: "无效",value: 0}
];
mini.get("bpqState").setData(PwdQuesFormHandler.bpqStateData);

/**
 * 保存（添加或编辑）数据的方法
 */
PwdQuesFormHandler.save = function(){
	var pwdQuesData = PwdQuesFormHandler.pwdQuesForm.getData();
	pwdQuesData.bpqId = PwdQuesFormHandler.formData.bpqId;
	
    PwdQuesFormHandler.pwdQuesForm.validate();
    if (PwdQuesFormHandler.pwdQuesForm.isValid() == false) return;
    
    var json = mini.encode(pwdQuesData);
    $.ajax({
        url: __root + "/saveOrUpdateBpq.do",
        type: "POST",
        data: {
        	bpqInfo: json,
        	lslUser: gbOperateUser,
    		lslAddress: gbOperateIp
        },
        cache: false,
        success: function (text) {
        	MiniuiTools.miniInfo("系统提示","保存成功！", function(action){
        		PwdQuesFormHandler.closeCurrentWin("save");
        	});
        },
        error: function (jqXHR, textStatus, errorThrown) {
        	MiniuiTools.miniError("系统提示", jqXHR.responseText, function(){
            	PwdQuesFormHandler.closeCurrentWin();
            });
            
        }
    });
}

/**
 * 标准方法接口定义
 * @param {} data
 */
PwdQuesFormHandler.passData = function(data) {
    if (data.action == "edit") {
        //跨页面传递的数据对象，克隆后才可以安全使用
        data = mini.clone(data);
        PwdQuesFormHandler.formData.bpqId = data.bpqId;
        //根据id获取对应的密保问题信息
        $.ajax({ 
            url: __root + "/getBpqById.do?bpqId=" + data.bpqId,
            cache: false,
            dataType: 'json',
            success: function (text) {
                PwdQuesFormHandler.pwdQuesForm.setData(text);
            }
        });
    }else{
    	//默认密保问题状态为有效
    	mini.get("bpqState").setValue(1);
    }
}

/**
 * 关闭窗口
 * @param {} action
 */
PwdQuesFormHandler.closeCurrentWin = function(action) {
    if (window.CloseOwnerWindow) window.CloseOwnerWindow(action);
    else window.close();
}

PwdQuesFormHandler.closeMiniWin = function(){
	PwdQuesFormHandler.closeCurrentWin("cancel");
}